

/*! \file ntfs_index_tree.h
 *  \brief 
 */

#ifndef __NTFS__INDEX__TREE__
#define __NTFS__INDEX__TREE__

#define NTFS_INDEX_BUFFER_MAX_SIZE  4096

#include <stack>
using namespace std;

typedef stack<VCN> VSTACK;
typedef VSTACK* PSTACK;

bool
ntfs_index_tree_insert_entry( 
                              PINDEX_ENTRY p_new_entry,     \
                              bool b_is_skip,               \
                              PNTFS_CONTEXT p_context       \
                            );

bool
ntfs_index_tree_find_entry( 
                                   IN  ULONG                       u_key_len,          \
                                   IN  PVOID                       p_key_value,        \
                                   IN  bool                        b_is_skip,          \
                                   IN  PNTFS_CONTEXT               p_context,          \
                                   OUT PINDEX_ENTRY*               p_found,            \
                                   OUT PINDEX_ALLOCATION_BUFFER*   p_contain_buffer,   \
                                   OUT PSTACK                      p_parent_tail       \
                           );
bool 
ntfs_index_tree_insert_entry_into_root( 
                                           PINDEX_ENTRY    p_new_entry,       \
                                           PNTFS_CONTEXT   p_context,         \
                                           PINDEX_ENTRY    p_insert_point     \
                                      );

bool
ntfs_index_tree_insert_entry_into_buffer( 
                                             PINDEX_ALLOCATION_BUFFER p_buffer,          \
                                             PINDEX_ENTRY             p_new_entry,       \
                                             PNTFS_CONTEXT            p_context,         \
                                             PINDEX_ENTRY             p_insert_point,    \
                                             PSTACK                   p_parent_tail      \
                                         );

bool ntfs_index_tree_find_buffer( 
                                     IN VCN buffer_find_vcn,                         \
                                     IN PINDEX_ALLOCATION_BUFFER p_parent_buffer,    \
                                     IN PINDEX_ALLOCATION_BUFFER p_found_buffer,     \
                                     IN OUT PSTACK               p_parent_tail,      \
                                     OUT bool* error                                 \
                                );

bool ntfs_index_tree_fixup_empty_leaf( VCN empty_leaf_vcn );


#endif//__NTFS__INDEX__TREE__